

/*---------------------------------------------------------
   Initializes the effect. The data is a table of data 
   which was passed from the server.
---------------------------------------------------------*/
function EFFECT:Init( data )
	
	local Velocity 	= data:GetNormal() or Vector(0,0,1)
	local Pos = data:GetOrigin()

	local pitch = (Velocity:Angle() + Angle(180,0,0)).p
	Velocity = Angle(math.NormalizeAngle(pitch),Velocity.y,Velocity.r):Forward()
	
	local LightColor = render.GetLightColor( Pos ) * 255
	LightColor.r = math.Clamp( LightColor.r, 70, 255 )
	LightColor.g = math.Clamp( LightColor.g, 70, 255 )
	LightColor.b = math.Clamp( LightColor.b, 70, 255 )
	
	local emitter = ParticleEmitter( Pos )
	
		for i= 1, math.random(4,8) do
			local particle = emitter:Add( "effects/blood_core", Pos + VectorRand() * math.Rand( -8, 8 ) )
				particle:SetVelocity( VectorRand() * math.Rand( -30, 30 ) )
				particle:SetDieTime( math.Rand( 0.1, 0.3 ) )
				particle:SetStartAlpha( 250 )
				particle:SetStartSize( math.Rand( 8, 16 ) )
				particle:SetEndSize( math.Rand( 48, 64 ) )
				particle:SetRoll( math.Rand( 0, 360 ) )
				particle:SetRollDelta( math.Rand( -0.5, 0.5 ) )
				particle:SetColor( LightColor.r*0.5, 0, 0 )
		end
	
		// blood spray
		for i=1, math.random(3,6) do
		
			local particle = emitter:Add( "effects/blood", Pos )

			particle:SetVelocity( Velocity * math.Rand( 150, 200 ) + VectorRand() * math.Rand( 20, 40 ) )
			particle:SetDieTime( math.Rand( 0.5, 1.0 ) )
			particle:SetStartAlpha( 200 )
			particle:SetEndAlpha( 128 )
			particle:SetStartSize( math.Rand( 8, 10 ) )
			particle:SetRollDelta( math.Rand( -0.5, 0.5 ) )
			particle:SetColor( LightColor.r*0.5, 0, 0 )
			
		end
		
		// Random blood squirts (forward)
		for i=1, math.random(5,10) do
		
			local particle = emitter:Add( "effects/blooddrop", Pos )

			particle:SetVelocity( Velocity * math.Rand( 100, 300 ) + VectorRand() * math.Rand( 50, 200 ) )
			particle:SetDieTime( math.Rand( 4, 5 ) )
			particle:SetStartAlpha( 200 )
			particle:SetEndAlpha( 1 )
			particle:SetStartSize( math.Rand( 1, 2 ) )
			particle:SetRollDelta( math.Rand( -0.1, 0.1 ) )
			particle:SetColor( LightColor.r*0.5, 0, 0 )
			particle:SetRoll( math.Rand( 0, 360 ) )
			
			particle:SetGravity(Vector(0,0,-550))
			particle:SetCollide(true)
			particle:SetBounce(0.01) 
			
		end
				
	emitter:Finish()
	
end


/*---------------------------------------------------------
   THINK
   Returning false makes the entity die
---------------------------------------------------------*/
function EFFECT:Think( )

	// Die instantly
	return false
	
end


/*---------------------------------------------------------
   Draw the effect
---------------------------------------------------------*/
function EFFECT:Render()

	// Do nothing - this effect is only used to spawn the particles in Init
	
end



